package com.lhz.project.system.task.service;

import cn.hutool.json.JSONUtil;
import com.lhz.project.system.task.pojo.TaskOne;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @Author: LiHuaZhi
 * @Date: 2021/2/29 18:34
 * @Description:
 **/
@Slf4j
@Service("taskBusinessService")
public class TaskBusinessService {

    /**
     * 为了记录异常 所有的方法必须在try内
     * 每个方法默认接收一个taskId
     */
    public void taskA(String text) throws InterruptedException {
        log.info("======执行业务代码 --- this is A======");
        TaskOne taskOne = JSONUtil.toBean(text, TaskOne.class);
        log.info("TaskOne-Id：{},TaskOne-Amount：{}", taskOne.getId(), taskOne.getAmount());
        //模拟时长
        int number = new Random().nextInt(100) + 1;
        Thread.sleep(number);
    }

    public void taskB(String text) throws InterruptedException {
        log.info("======执行业务代码 --- this is B======");
        //模拟时长
        int number = new Random().nextInt(100) + 1;
        Thread.sleep(number);
    }
}
